<?php
namespace app\admin\controller;

use think\Controller;

class User extends Controller {

    public function index()
    {
        if(request()->isPost()){
            $data=input('post.');
            if(empty($data['form-username'])||empty($data['form-password'])){
                return $this->error('账号或密码不能为空');
            }
            $user=model('Admin');
            $res=$user->getInfoByUserName($data['form-username']);

            if($res){
                if($res['upwd']==md5($data['form-password'])){
                    cookie('aduid',$res['id']);
                    return $this->success('登陆成功',url('index/index'),'',1);
                }else{
                    return $this->error('账号或密码错误',url('user/index'),'',1);
                }
            }else{

                return $this->error('登陆失败',url('user/index'),'',1);
            }
        }
        return $this->fetch();
    }

    public function outlogin(){
        cookie('aduid',null);
        return $this->error('退出成功',url('admin/user/index'),'',1);
    }
}